package com.stx.day0918;

import java.util.Objects;

/**
 * packageName com.stx.day0918
 *
 * @author YangYi
 * @className Student
 * @date 2025/9/18
 * @description TODO
 */
public class Student {
    private String name;
    private int id;

    public Student(String name, int id) {
        this.name = name;
        this.id = id;
    }

    /**
     * 需要去比较对象里的学号是否一致-id
     */
    @Override
    public boolean equals(Object obj) {
//        return super.equals(obj);
        if(this == obj){// 会有基本数据类型
            return true;
        }
        if(obj == null || this.getClass() != obj.getClass()){
            return false;
        }
        Student student = (Student) obj;
        return this.id == student.id;
    }

    @Override
    public int hashCode() {
//        return super.hashCode();
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", id=" + id +
                '}';
    }
}
